<template>
  <div class="intro-container" element-loading-background="transparent" v-loading="loading">
    <div class="header">
      <div
        @click="handleBtn(item, index)"
        class="item"
        :class="{ actived: isActive == index }"
        v-for="(item, index) in tabList"
        :key="index"
      >{{ item.name }}</div>
    </div>
    <div class="content">
      <el-scrollbar>
        <div class="item" v-for="(item, index) in itemList" :key="index">
          <div class="left">
            <img @click="handlePreview(item.imgList)" src="@img/ztxx/glzd1.png" alt />
            <!-- <el-image
              :preview-src-list="item.imgList"
              fit="contain"
              src="src/assets/images/ztxx/glzd1.png"
            />-->
          </div>
          <div class="right">
            <div class="title">{{ item.title }}</div>
            <div class="time">{{ item.createTime }}</div>
            <div class="titleSub">{{ item.titleSub }}</div>
          </div>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script setup>
import { getShiCGLZD, getSmallShiCGLZD } from "@/apis/subjectInfo";
import { ref } from "vue";
const tabList = ref();
const itemList = ref();
const isActive = ref(0);
const loading = ref(false);

const getInfo = () => {
  loading.value = true;
  getShiCGLZD().then(res => {
    tabList.value = res.data;
    getSmallinfo(res.data[0].id);
    loading.value = false;
  });
};
getInfo();

const handleBtn = (item, index) => {
  isActive.value = index;
  getSmallinfo(item.id);
};

const getSmallinfo = id => {
  getSmallShiCGLZD(id).then(res => {
    itemList.value = res.data;
  });
};

const handlePreview = list => {
  showImagePreview({ images: list, closeable: true });
};
</script>

<style lang="scss" scoped>
.intro-container {
  height: 100%;
  overflow: hidden;
  .header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    display: grid;
    grid-row-gap: 1px;
    justify-content: space-around;
    align-content: center;
    grid-template-columns: repeat(auto-fill, 130px);
    .item {
      height: 12px;
      font-weight: 400;
      font-size: 12px;
      color: #e7eaf3;
      line-height: 12px;
      text-align: center;
      border-radius: 20px;
      border: 1px solid #fff;
      padding: 8px 10px 8px 10px;
      margin-bottom: 11px;
    }
    .actived {
      font-size: 12px;
      transition: all 0.3s;
      background-color: #ffffff;
      color: #103b97;
      font-weight: 600;
    }
  }
  .content {
    height: 350px;
    // height: 100%;
    padding: 10px 0;
    .item {
      // height: 97px;
      margin-bottom: 16px;
      display: flex;
      .left {
        width: 143px;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
          // height: 100%;
          width: 100%;
        }
        .el-image {
          border-radius: 10px;
          width: 100%;
          height: 97px;
        }
      }
      .right {
        margin-left: 12px;
        width: 268px;
        display: flex;
        flex-direction: column;
        .title {
          font-size: 15px;
          font-weight: bold;
          color: #fff;
        }
        .time {
          margin-top: 4px;
          font-size: 9px;
          color: #e7eaf3;
        }
        .titleSub {
          margin-top: 6px;
          font-size: 8px;
          color: #e7eaf3;
        }
      }
    }
  }
}
</style>
